/*
 * @Author: sxb
 * @Email: sxb@mail.com
 * @Date: 2020-02-17 17:50:36
 * @Descripttion: 
 */
import { Component, OnInit } from '@angular/core';
import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
import { AccountaliasManageService } from './accountalias-manage.service';
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
    selector: 'app-accountalias-manage',
    templateUrl: './accountalias-manage.component.html',
    styleUrls: ['./accountalias-manage.component.scss']
})
export class AccountaliasManageComponent implements OnInit {
    private erpConfirmModal: NzModalRef;
    txtAlias: any = '';

    //--分页部分
    pageIndex: any = '1';//table当前页
    pageSize: any = '10';//table每页条数
    totalSize: any = '';//总共条数
    listOfData = [];

    constructor(
        private AccountaliasService: AccountaliasManageService,
        private modal: NzModalService,
        private message: NzMessageService
    ) { }

    ngOnInit() {
        this.getAllData()
    }

    // table页码点击事件
    clickPage(current) {
        this.pageIndex = current
        this.getAllData()
    }
    // 获取右侧人员表格
    async getAllData() {
        let data = {
            alias: this.txtAlias,
            page: this.pageIndex - 1,
            size: this.pageSize
        }
        let list: any = await this.AccountaliasService.getFindAll(data).subscribe(res => {
            this.totalSize = res.totalElements
            this.listOfData = res.content;
        });
    }
    getAliasData() {
        this.getAllData();
    }
    private isLoading=false;
    getErpData():void {
        this.erpConfirmModal = this.modal.confirm({
            nzTitle: '获取ERP数据提示',
            nzContent: '确定要获取数据吗？',
            nzOnOk: () =>
            {
                this.isLoading = true;
                this.AccountaliasService.erpData().subscribe(res=>{
                    this.isLoading=false;
                    this.message.info("获取成功")
                    this.getAllData();
                },err=>{
                        // let errorMessage = err.error.message;
                        // this.message.create("error", errorMessage);
                        this.isLoading=false;
                });
            }
            //     new Promise((resolve, reject) => {
            //         //事件
            //          this.txtAlias = '';
            //          this.getAllData();
            //     }).catch(() => console.log('导入失败')),
            // nzOnCancel: ()=>{
               
            // }
        });
    }
}
